package com.atguigu.ai.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @author Jungle
 * @create 2025-03-01 12:03
 */
@RestController
@RequestMapping("/openai")
public class OpenAIChatController {
    @Resource
    private OpenAiChatModel chatModel;

    @GetMapping("/ai/generate")
    public String chat(@RequestParam String message) {
        return chatModel.call(message);
    }


    @GetMapping("/ai/generateStream")
    public Flux<String> chatStream(@RequestParam String message) {
        // Prompt prompt = new Prompt(new UserMessage(message));
        return  chatModel.stream(message);
    }
}
